home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Special 25 / AMIGAplus Sonderheft 25 (2000)(Falke)(DE)(Track 1 of 4)[!].iso / Updates / HD-Installer / CaptainPlanetHD / src / planet.asm < prev    next >
Assembly Source File  |  2000-05-11  |  6KB  |  249 lines

  1. ; Captain Planet HD loader
  2. ; v1.0: saves hiscores, copylocks removed, Captive disk cheat implemented
  3. ; by Kyzer/CSG
  4.  
  5.     include    whdload.i
  6.     include    whdmacros.i
  7.  
  8. MEM=$80000
  9.  
  10. base    SLAVE_HEADER
  11.     dc.w    10,WHDLF_NoError
  12.     dc.l    MEM,0        ; basemem, 0
  13.     dc.w    start-base,0,0        ; slave code, dir, dontcache
  14.     dc.b    0,$59            ; debugkey, quitkey
  15.     dc.l    0            ; expmem
  16.     dc.w    name-base,copy-base,info-base
  17. name    dc.b    'Captain Planet',0
  18. copy    dc.b    '1991 Mindscape',0
  19. info    dc.b    'HD-installed by Kyzer',0
  20. resload    dc.l    0
  21. tags    dc.l    WHDLTAG_CUSTOM1_GET
  22. trainer    dc.l    0,TAG_DONE
  23. start    lea    resload(pc),a1
  24.     move.l    a0,(a1)+
  25.     move.l    a0,a2
  26.  
  27.     lea    tags(pc),a0
  28.     jsr    resload_Control(a2)
  29.  
  30.     lea    MEM,a4            ; a4 = top of memory
  31.     lea    -$4870(a4),a5        ; a5 = decoded bootblock addr
  32.     lea    .boot(pc),a0
  33.     move.l    a5,a1
  34.     jsr    resload_LoadFile(a2)    ; load bootcode
  35.     patch    $56(a5),.cont        ; stop bootcode at loading ratt-dos
  36.     jmp    (a5)            ; run bootcode
  37. .cont    move.w    #$8000!DMAF_MASTER!DMAF_RASTER!DMAF_COPPER,_custom+dmacon
  38.  
  39.     lea    $124.w,a6        ; a6 = ratt-dos base
  40.     lea    .ratt(pc),a0
  41.     move.l    a6,a1
  42.     jsr    resload_LoadFile(a2)    ; load ratt-dos
  43.     lea    .patch(pc),a0
  44.     move.l    a6,a1
  45.     jsr     resload_Patch(a2)    ; patch ratt-dos
  46.     move.l    a6,4.w            ; save at 0
  47.     move.l    a6,0.w            ; save at 4
  48.     lea    $2000(a6),a0        ; initialise ratt-dos
  49.     lea    .datas(pc),a1
  50.     jsr    $68(a6)
  51.     jmp    MEM-$4870+$fc        ; back to bootcode
  52.  
  53. .datas    dc.l    0,$32320000,0,MEM,0,0
  54. .boot    dc.b    'bootcode',0
  55. .ratt    dc.b    'rattdos',0
  56.     cnop    0,4
  57.  
  58. ; ratt-dos functions            ;$40 OK    'get existing drives'
  59. ;$00 OK(5) 'init drives with sync'    ;$44 ALERT ??? writes directory
  60. ;$04 OK(5) 'init drives'        ;$48 ALERT 'rename file'
  61. ;$08 PATCH 'set directory buffer'    ;$4C ALERT ??? writes something
  62. ;$0C OK    'set data buffer'        ;$50 OK    empty function
  63. ;$10 PATCH 'raw read'            ;$54 OK    'get buffers'
  64. ;$14 PATCH 'save file'            ;$58 OK(1) 'find dir entry'
  65. ;$18 ALERT ???                ;$5C OK    'set sync'
  66. ;$1C PATCH 'load file'            ;$60 OK(1) 'change disk'
  67. ;$20 OK(4) 'motor off'            ;$64 OK(4) 'specific motor off'
  68. ;$24 OK    'restore ints'        ;$68 OK    'initialise'
  69. ;$28 OK    'set/store ints'        ;$6C OK    memory function
  70. ;$2C ALERT 'set directory size'        ;$70 OK    'free memory'
  71. ;$30 ALERT 'clear directory'        ;$74 OK    'allocate memory'
  72. ;$34 ALERT 'get empty track'        ;$78 OK    'set drive parameters'
  73. ;$38 OK2&3 'get disk dir'        ;$7C OK    'alloc mem with type'
  74. ;$3C OK    'reset drives'        ;$80 OK    'get memory info'
  75.  
  76. .patch    PL_START
  77.     ; removal of internal disk-accessing ratt-dos functions
  78.     PL_L    $7b0,$70004e75        ; (1) 'find disk and load directory'
  79.     PL_R    $3ec            ; (2) 'select drive'
  80.     PL_R    $4a0            ; (3) 'read disk dir'
  81.     PL_R    $67a            ; (4) 'motor off'
  82.     PL_R    $5ec            ; (5) 'init drives'
  83.     ; patches of external functions
  84.     PL_P    $1c2,setdir
  85.     PL_P    $2ec,load
  86.     PL_P    $82a,rawread
  87.     PL_P    $86a,rawwrit
  88.  
  89.     ; alerts
  90.     PL_I    $18
  91.     PL_I    $2c
  92.     PL_I    $30
  93.     PL_I    $34
  94.     PL_I    $44
  95.     PL_I    $48
  96.     PL_I    $4c
  97.     PL_END
  98.  
  99. ;SETDIR: d0 = new buffer
  100. setdir    movem.l    d0-d1/a0-a2,-(sp)
  101.     move.l    d0,($124+$f6e).w    ; save dir pointer
  102.     move.l    d0,a1
  103.     lea    .cpdir(pc),a0
  104.     move.l    resload(pc),a2
  105.     jsr    resload_LoadFile(a2)    ; read in copy of dir
  106.     movem.l    (sp)+,d0-d1/a0-a2
  107.     rts
  108. .cpdir    dc.b    'cp.dir',0
  109.     cnop    0,4
  110.  
  111. ;RAWREAD: d0 = sync, d2 = track, d3 = length
  112. rawread    swap    d2
  113.     move.w    d0,d2
  114.     cmp.l    #$00034489,d2    ; load hiscores
  115.     beq.s    .hisc
  116.     cmp.l    #$00024489,d2    ; DO NOTHING - return OK (protection check)
  117.     beq.s    .ok
  118.     cmp.l    #$00024522,d2    ; DO NOTHING - fail (Captive disk check)
  119.     beq.s    .fail
  120.     illegal            ; fail on any other values
  121. .hisc    move.l    (a4),a1
  122.     addq.l    #4,a1
  123.     lea    hisc(pc),a0
  124.     move.l    resload(pc),a2
  125.     jsr    resload_LoadFile(a2)
  126.     move.l    (a4),a1
  127. .ok    clr.l    $60.w
  128.     rts
  129. .fail    move.l    #-4,$60.w
  130.     rts
  131.  
  132. ;RAWWRITE:
  133. rawwrit    cmp.w    #$0003,d2
  134.     beq.s    .hisc        ; save hiscores
  135.     illegal            ; fail anything else
  136. .hisc    move.l    a0,a1
  137.     lea    hisc(pc),a0
  138.     moveq    #48,d0
  139.     move.l    resload(pc),a2
  140.     jmp    resload_SaveFile(a2)
  141.  
  142. hisc    dc.b    'HI-Score',0
  143.     cnop    0,4
  144.  
  145. ;LOAD:
  146. ; in:  a0 = load address, a1 = filename, d1 =  magic unpacking number?
  147. ; out: a0 = load address + length, $60.l = length
  148. load    movem.l    d0-d2/a1-a2,-(sp)
  149.     exg.l    a0,a1        ; a0=fname, a1=loadaddr
  150.     cmp.b    #':',2(a0)
  151.     bne.s    1$        ; name "CP:xyz" -> "xyz"
  152.     addq.l    #3,a0
  153. 1$    move.l    a0,-(sp)
  154.     moveq    #4-1,d0
  155.     lea    .name(pc),a2
  156. .cp    move.b    (a0)+,(a2)+    ; copy 4 bytes of name
  157.     dbra    d0,.cp
  158.     move.l    (sp)+,a0
  159.  
  160.     move.l    a1,-(sp)    ; save load address
  161.     move.l    resload(pc),a2
  162.     jsr    resload_LoadFile(a2)
  163.     move.l    d0,d2
  164.  
  165.     move.l    (sp),a1        ; a1 = load address
  166.     lea    .name(pc),a0
  167.     cmp.l    #'CP'<<16,(a0)    ; compare filename loaded to "CP"
  168.     bne.s    2$
  169.     bsr.s    patchcp        ; patch main CP executable
  170.     bra.s    .done
  171. 2$    cmp.l    #'cpbo',(a0)    ; compare filename loaded to "cpboot"
  172.     bne.s    .done
  173.     ret    $1be(a1)    ; remove cpboot's debugger
  174.  
  175. .done    move.l    d2,$60.w    ; $60.w = load length
  176.     move.l    (sp)+,a0    ; a0 = load address
  177.     add.l    d2,a0        ; a0 = load address + load length
  178.     movem.l    (sp)+,d0-d2/a1-a2
  179.     rts
  180.  
  181. .name    dc.l    0
  182.  
  183.     
  184. ;------------------------------------------------------------------------------
  185.  
  186. patchcp    move.l    trainer(pc),d0
  187.     bne.s    1$
  188.     lea    .cheats(pc),a0        ; if cheat-mode is disabled then
  189.     move.w    #PLCMD_END,(a0)        ; cut off the cheat patches
  190. 1$    lea    .patch(pc),a0
  191.     adda.w    #$20,a1            ; a1 = $5a9c
  192.     move.l    resload(pc),a2
  193.     jmp    resload_Patch(a2)
  194. .patch    PL_START
  195.     PL_B    $1a56,$60        ; remove mem checksum (beq.s -> bra.s)
  196.     PL_B    $32ee,$60        ; remove mem checksum (beq.s -> bra.s)
  197.     PL_R    $15a0            ; remove some drive access
  198.     PL_P    $a2d0,.lock1        ; decoded copylock
  199.     PL_P    $9c0a,.lock2        ; decoded copylock
  200. .cheats    PL_B    $3bbc,$60        ; livescheat (bne.s -> bra.s)
  201.     PL_B    $9fd8,$60        ; levelcheat (bne.s -> bra.s)
  202.     PL_B    $a036,$60        ; levelcheat (bne.s -> bra.s)
  203.     PL_END
  204.  
  205. .lock1    move.l    #$92385060,d3
  206.     bra.s    .lock
  207. .lock2    move.l    #$52613060,d3
  208. .lock    movem.l    d0-d7/a0-a7,-(sp)
  209.     move.l    #$43896371,d0
  210.     moveq    #0,d1
  211.     move.l    sp,a6
  212.  
  213.     move.l    d0,$60.w
  214.     moveq    #3,d3
  215.     move.l    d1,4(a6)
  216.  
  217. .outer    lsl.w    #2,d3
  218.     move.l    (a6,d3.w),d2
  219.     rol.w    #4,d2
  220.     andi.b    #%00001111,d2
  221.     beq.b    .done
  222.     subi.w    #$1000,2(a6,d3.w)
  223.     move.l    (a6,d3.w),d3
  224.     rol.w    #8,d3
  225.     move.w    d3,d1
  226.     andi.w    #7,d1
  227.     lsl.w    #2,d1
  228.     movea.l    $20(a6,d1.w),a0
  229.     rol.w    #4,d3
  230.     move.w    d3,d1
  231.     andi.w    #7,d1
  232.     lsl.w    #2,d1
  233.     move.l    (a6,d1.w),d1
  234. .inner    movea.l    (a0)+,a1
  235.     add.l    d0,(a1,d1.l)
  236.     subq.b    #1,d2
  237.     bne.b    .inner
  238.     rol.w    #4,d3
  239.     andi.w    #15,d3
  240.     cmp.b    #8,d3
  241.     blt.b    .outer
  242. .done    cmp.l    $60.w,d0
  243.     beq.s    .ok
  244.     illegal
  245. .ok    move.l    resload(pc),a6
  246.     jsr    resload_FlushCache(a6)
  247.     movem.l    (sp)+,d0-d7/a0-a7
  248.     rts
  249.